package org.zoomdev.zoom;

import org.zoomdev.zoom.dao.annotations.AutoGenerate;
import org.zoomdev.zoom.dao.annotations.Column;
import org.zoomdev.zoom.dao.annotations.ColumnIgnore;
import org.zoomdev.zoom.dao.annotations.Table;

@Table("sys_ensure")
public class Job {

    public static final String TABLE = "sys_ensure";

    public boolean isComplete() {
        return state == State.success || state == State.done;
    }

    public byte[] getException() {
        return exception;
    }

    public void setException(byte[] exception) {
        this.exception = exception;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public enum State {
        init,
        fail,
        success,

        /**
         * 达到最大重试次数之后还是失败
         */
        maxRetry,

        done
    }

    @AutoGenerate
    private Integer id;
    private Integer type;


    private byte[] data;
    private State state;

    private int retry;


    private byte[] exception;


    @ColumnIgnore
    private int h;

    @Override
    public int hashCode() {
        int h = this.h;
        if (h == 0) {
            h = 31 * id;
            this.h = h;
        }
        return h;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }




    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getRetry() {
        return retry;
    }

    public void setRetry(int retry) {
        this.retry = retry;
    }




    @Override
    public boolean equals(Object obj) {
        if (obj == null || (!(obj instanceof Job))) {
            return false;
        }
        Job other = (Job) obj;
        return id == other.id;
    }


}
